<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<script src="../js/mui.min.js"></script>
		 <script src="../js/app.js"></script>
		<script type="text/javascript">
mui.init({  
                    subpages:[//先加载首页  
                        {  
                          url:'../item/index.html',  
                          id:'a1',  
                          styles:{  
                             top:'0px',  
                                bottom:'0px'  
                          }  
                        }  
                          
                    ],  
                    preloadPages:[//缓存其他页面  
                        {  
                          url:'../item/index.html',  
                          id:'a2',  
                          styles:{  
                             top:'0px',  
                            bottom:'0px'  
                          }  
                        },  
                        {  
                          url:'../tongxun/index.html',  
                          id:'a3',  
                          styles:{  
                             top:'0px',  
                            bottom:'0px'  
                          }  
                        },
                        {  
                          url:'../admin/index.html',  
                          id:'a4',  
                          styles:{  
                             top:'0px',  
                            bottom:'0px'  
                          }  
                        } 
                    ]  
                      
                });  
            mui.plusReady(function(){   
                // 获取所有Webview窗口  
                var winAll=plus.webview.all();//获取所有窗体  
                //console.log(JSON.stringify(winAll))   
                var a1,a2,a3,a4; 
                mui("#nav").on("tap","#a1",function(){//点击触发   
                    a1=plus.webview.getWebviewById("a1");  
                    console.log(JSON.stringify(a1))   
                    a1.show()  
                    a2.hide()//这一步必须有  
                    a3.hide()//这一步必须有  
                    a4.hide()//这一步必须有  
                })  
                mui("#nav").on("tap","#a2",function(){//点击触发  
                    a2=plus.webview.getWebviewById("a2");  
                    a2.show()  
                      
                })  
                mui("#nav").on("tap","#a3",function(){//点击触发  
                    a3=plus.webview.getWebviewById("a3");  
                    a3.show()  
                      
                })  
                mui("#nav").on("tap","#a4",function(){//点击触发  
                    a4=plus.webview.getWebviewById("a4");  
                    a4.show()  
                      
                }) 
            });  
		</script>
		</head>
		<body>
		<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">影人联盟</h1>
	</header>
	<nav class="mui-bar mui-bar-tab" id="nav">
        <a class="mui-tab-item mui-active" id="home">
            <span class="mui-icon mui-icon-home"></span>
            <span class="mui-tab-label">首页</span>
        </a>
        <a class="mui-tab-item" id="a2">
            <span class="mui-icon mui-icon-chatboxes"></span>
            <span class="mui-tab-labe2">消息</span>
        </a>
        <a class="mui-tab-item" id="a3">
            <span class="mui-icon-extra mui-icon-extra-peoples"></span>
            <span class="mui-tab-labe3">好友</span>
        </a>
        <a class="mui-tab-item" id="a4">
            <span class="mui-icon mui-icon-person" onclick="my()"></span>
            <span class="mui-tab-labe4">我的</span>
        </a>
    </nav>
    <script type="text/javascript">
//  	alert(home.hos);//域名
function my() {
//检查用户信息是否存在本地数据库，不存在连接服务器下载
ckey="my";
jsonData={username:'enen',passw:'acme'};//请求信息
kval = localStorage.getItem(ckey); 
localStorage.removeItem(ckey);//清空数据/
if(kval==null || kval=="" || kval=="null"||kval==false){
	ajax('POST','http://192.168.1.107/login.php',jsonData,function(str){//读取a.txt文件里面的内容
str=str.trim(']', 'right'); // /Ruchee 
str=str.trim('[', 'left'); // Ruchee/
alert(str);//将读取的内容输出
localStorage.setItem(ckey,str); 
	},'text');
}else{
//	return false;
//Tajax();
}}
function Tajax()
{
ckey="friends";
kval = localStorage.getItem(ckey); 
localStorage.removeItem(ckey);//清空数据/
if(kval==null || kval=="" || kval=="null"||kval==false){
jsonData={username:'enen',passw:'acme'};//请求信息
   ajax('POST','http://192.168.1.107/login.php',jsonData,function(str){//读取a.txt文件里面的内容
str=str.trim(']', 'right'); // /Ruchee 
str=str.trim('[', 'left'); // Ruchee/
alert(str);//将读取的内容输出
localStorage.setItem(ckey,str);
 },'text');            
}else{
var mess="";
sttt =eval("(["+kval+"])");
stt =eval("("+kval+")");
//alert("数据库已经有文件"+kval+sttt);
result=uniqueArray(sttt,"id");
	for(var i=0;i<result.length;i++){
mess+='{"id":"'+result[i].id+'","addtime":"'+result[i].addtime+'","message":"'+result[i].message+'"},';
//      alert(jsonObj[i].id);  //取json中的值
} 
 mess=mess.trim(',','right');//每次连接完毕删除结尾逗号
alert("数据库新添加文件"+mess);
}
}

/*
 * JSON数组去重
 * @param: [array] json Array
 * @param: [string] 唯一的key名，根据此键名进行去重
 * 使用方法 result=uniqueArray("[{"id":"5"}{"id":"5"}]","id");返回的result会删除相同id后返回数组
 */
function uniqueArray(array, key){
    var result = [array[0]];
    for(var i = 1; i < array.length; i++){
        var item = array[i];
        var repeat = false;
        for (var j = 0; j < result.length; j++) {
            if (item[key] == result[j][key]) {
                repeat = true;//遇到相同值无输出
                break;
            }
        }
        if (!repeat) {
        	//遇到不同的值装进数组
            result.push(item);
        }
    }
    //返回一个数组
    return result;
}
//localStorage.setItem(ckey,mess);
</script>
	</body>

</html>